home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / misc / emu / amiSPIMsrc.lha / inst.h < prev    next >
C/C++ Source or Header  |  1994-01-17  |  6KB  |  247 lines

  1. /* SPIM S20 MIPS simulator.
  2.    Description of a SPIM S20 instruction.
  3.    (Layout does not correspond to MIPS machine.)
  4.    Copyright (C) 1990-1994 by James Larus (larus@cs.wisc.edu).
  5.    ALL RIGHTS RESERVED.
  6.  
  7.    SPIM is distributed under the following conditions:
  8.  
  9.      You may make copies of SPIM for your own use and modify those copies.
  10.  
  11.      All copies of SPIM must retain my name and copyright notice.
  12.  
  13.      You may not sell SPIM or distributed SPIM in conjunction with a
  14.      commerical product or service without the expressed written consent of
  15.      James Larus.
  16.  
  17.    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  18.    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  19.    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.    PURPOSE. */
  21.  
  22.  
  23. /* $Header: /home/primost/larus/Software/SPIM/RCS/inst.h,v 3.10 1994/01/18 03:21:45 larus Exp larus $
  24. */
  25.  
  26.  
  27. /* Describes an expression that produce a value for an instruction's
  28.    immediate field.  Immediates have the form: label +/- offset. */
  29.  
  30. typedef struct immexpr
  31. {
  32.   long offset;            /* Offset from symbol */
  33.   struct lab *symbol;        /* Symbolic label */
  34.   short bits;            /* > 0 => 31..16, < 0 => 15..0 */
  35.   short pc_relative;        /* Non-zero => offset from label in code */
  36. } imm_expr;
  37.  
  38.  
  39. /* Describes an expression that produce an address for an instruction.
  40.    Address have the form: label +/- offset (register). */
  41.  
  42. typedef struct addrexpr
  43. {
  44.   unsigned char reg_no;        /* Register number */
  45.   imm_expr *imm;        /* The immediate part */
  46. } addr_expr;
  47.  
  48.  
  49.  
  50. /* Store the instruction fields in an overlapping manner similar to
  51.    the real encoding. */
  52.  
  53. typedef struct inst_s
  54. {
  55.   short opcode;
  56.  
  57.   union
  58.     {
  59.       /* R-type or I-type: */
  60.       struct
  61.     {
  62.       unsigned char rs;
  63.       unsigned char rt;
  64.  
  65.       union
  66.         {
  67.           short imm;
  68.  
  69.           struct
  70.         {
  71.           unsigned char rd;
  72.           unsigned char shamt;
  73.         } r;
  74.         } r_i;
  75.     } r_i;
  76.  
  77.       /* J-type: */
  78.       long target;
  79.     } r_t;
  80.  
  81.   unsigned long encoding;
  82.   imm_expr *expr;
  83.   char *source_line;
  84. } instruction;
  85.  
  86.  
  87. #define OPCODE(INST)    (INST)->opcode
  88.  
  89. #define RS(INST)    (INST)->r_t.r_i.rs
  90. #define FS(INST)    (INST)->r_t.r_i.rs
  91. #define BASE(INST)    (INST)->r_t.r_i.rs
  92.  
  93. #define RT(INST)    (INST)->r_t.r_i.rt
  94. #define FT(INST)    (INST)->r_t.r_i.rt
  95.  
  96. #define RD(INST)    (INST)->r_t.r_i.r_i.r.rd
  97. #define FD(INST)    (INST)->r_t.r_i.r_i.r.rd
  98.  
  99. #define SHAMT(INST)    (INST)->r_t.r_i.r_i.r.shamt
  100.  
  101. #define IMM(INST)    (INST)->r_t.r_i.r_i.imm
  102. #define IOFFSET(INST)    (INST)->r_t.r_i.r_i.imm
  103. #define COND(INST)    (INST)->r_t.r_i.r_i.imm
  104.  
  105. #define TARGET(INST)    (INST)->r_t.target
  106.  
  107. #define ENCODING(INST)    (INST)->encoding
  108.  
  109. #define EXPR(INST)    (INST)->expr
  110.  
  111. #define SOURCE(INST)    (INST)->source_line
  112.  
  113.  
  114. #define COND_UN        0x1
  115. #define COND_EQ        0x2
  116. #define COND_LT        0x4
  117. #define COND_IN        0x8
  118.  
  119.  
  120.  
  121. /* Raise an exception! */
  122.  
  123. #define RAISE_EXCEPTION(CAUSE, MISC)                    \
  124.     {                                \
  125.       if (((CAUSE)<= LAST_REAL_EXCEPT) || (Status_Reg & 0x1))    \
  126.         {                                \
  127.           Cause = (CAUSE) << 2;                    \
  128.           exception_occurred = 1;                    \
  129.           EPC = PC;                            \
  130.           Status_Reg = (Status_Reg & 0xffffffc0) | ((Status_Reg & 0xf) << 2); \
  131.           MISC;                            \
  132.         }                                \
  133.     }                                \
  134.  
  135.  
  136. #define CL_RAISE_EXCEPTION(enum, cnum, excpt)                         \
  137.   (excpt) = ((cnum) << 28) | ((enum) << 2) | 0x1;
  138.  
  139.  
  140. /* Recognized exceptions (see Ch. 5): */
  141.  
  142. #define INT_EXCPT 0
  143. #define MOD_EXCPT 1
  144. #define TLBL_EXCPT 2
  145. #define TLBS_EXCPT 3
  146. #define ADDRL_EXCPT 4
  147. #define ADDRS_EXCPT 5
  148. #define IBUS_EXCPT 6
  149. #define DBUS_EXCPT 7
  150. #define SYSCALL_EXCPT 8
  151. #define BKPT_EXCPT 9
  152. #define RI_EXCPT 10
  153. #define CPU_EXCPT 11
  154. #define OVF_EXCPT 12
  155.  
  156. #define CACHEABLE 13
  157. #define NOT_CACHEABLE 14
  158.  
  159.  
  160. /* Floating point exceptions (Ch. 8): */
  161.  
  162. #define INEXACT_EXCEPT 13
  163. #define INVALID_EXCEPT 14
  164. #define DIV0_EXCEPT 15
  165. #define FOVF_EXCEPT 16
  166. #define FUNF_EXCEPT 17
  167.  
  168. #define LAST_REAL_EXCEPT FUNF_EXCEPT
  169.  
  170.  
  171.  
  172. /* Exported functions: */
  173.  
  174. #ifdef __STDC__
  175. imm_expr *addr_expr_imm (addr_expr *expr);
  176. int addr_expr_reg (addr_expr *expr);
  177. imm_expr *const_imm_expr (long int value);
  178. imm_expr *copy_imm_expr (imm_expr *old_expr);
  179. instruction *copy_inst (instruction *inst);
  180. mem_addr current_text_pc (void);
  181. long eval_imm_expr (imm_expr *expr);
  182. void free_inst (instruction *inst);
  183. void i_type_inst (int opcode, int rt, int rs, imm_expr *expr);
  184. void i_type_inst_free (int opcode, int rt, int rs, imm_expr *expr);
  185. void increment_text_pc (int delta);
  186. imm_expr *incr_expr_offset (imm_expr *expr, long int value);
  187. instruction *inst_decode (unsigned long int value);
  188. long inst_encode (instruction *inst);
  189. int inst_is_breakpoint (mem_addr addr);
  190. void j_type_inst (int opcode, imm_expr *target);
  191. void k_text_begins_at_point ();
  192. void k_text_begins_at_point (mem_addr addr);
  193. imm_expr *lower_bits_of_expr (imm_expr *old_expr);
  194. addr_expr *make_addr_expr (long int offs, char *sym, int reg_no);
  195. imm_expr *make_imm_expr (int offs, char *sym, int pc_rel);
  196. int opcode_is_branch (int opcode);
  197. int opcode_is_jump (int opcode);
  198. int opcode_is_load_store (int opcode);
  199. void print_inst (mem_addr addr);
  200. int print_inst_internal (char *buf, int len, instruction *inst, mem_addr addr);
  201. void r_cond_type_inst (int opcode, int rs, int rt);
  202. void r_sh_type_inst (int opcode, int rd, int rt, int shamt);
  203. void r_type_inst (int opcode, int rd, int rs, int rt);
  204. instruction *set_breakpoint (mem_addr addr);
  205. void store_instruction (instruction *inst);
  206. void text_begins_at_point (mem_addr addr);
  207. imm_expr *upper_bits_of_expr (imm_expr *old_expr);
  208. void user_kernel_text_segment (int to_kernel);
  209. int zero_imm (imm_expr *expr);
  210. #else
  211. imm_expr *addr_expr_imm ();
  212. int addr_expr_reg ();
  213. imm_expr *const_imm_expr ();
  214. imm_expr *copy_imm_expr ();
  215. instruction *copy_inst ();
  216. mem_addr current_text_pc ();
  217. long eval_imm_expr ();
  218. void free_inst ();
  219. void i_type_inst ();
  220. void i_type_inst_free ();
  221. void increment_text_pc ();
  222. imm_expr *incr_expr_offset ();
  223. instruction *inst_decode ();
  224. long inst_encode ();
  225. int inst_is_breakpoint ();
  226. void j_type_inst ();
  227. void k_text_begins_at_point ();
  228. void k_text_begins_at_point ();
  229. imm_expr *lower_bits_of_expr ();
  230. addr_expr *make_addr_expr ();
  231. imm_expr *make_imm_expr ();
  232. int opcode_is_branch ();
  233. int opcode_is_jump ();
  234. int opcode_is_load_store ();
  235. void print_inst ();
  236. int print_inst_internal ();
  237. void r_cond_type_inst ();
  238. void r_sh_type_inst ();
  239. void r_type_inst ();
  240. instruction *set_breakpoint ();
  241. void store_instruction ();
  242. void text_begins_at_point ();
  243. imm_expr *upper_bits_of_expr ();
  244. void user_kernel_text_segment ();
  245. int zero_imm ();
  246. #endif
  247.